﻿using System;
using System.Collections.Generic;
using System.Text;

namespace StarBotDotNet.BuildStateCheckers
{
    public class StateCheckerAllocateResources:StateCheckerAbstract
    {

        protected override void InitiateMovingToThisState(IBuildingParty buildingParty, BuildTarget target, StarBotDotNet.ProxyBot bot, UnitDictionary currentUnits, int currentTime)
        {
      
        }

        protected override void AfterMovingToState(StarBotDotNet.ProxyBot bot, IBuildingParty buildingParty, BuildTarget target)
        {
            bot.Player.AlocateResources(target.UnitToBuild.MineralsCost, target.UnitToBuild.GasCost);
            target.SetResourcesAllocated(); 
            base.AfterMovingToState(bot, buildingParty, target);
        }

        protected override bool CanEnterThisState(IBuildingParty buildingParty, BuildTarget target, StarBotDotNet.ProxyBot bot, UnitDictionary currentUnits, int currentTime)
        {
            if (!bot.HasResources(target.UnitToBuild))
            {
                return false;
            }

            if (!target.HasBuilder())
            {
                target.Builder = buildingParty.FindUnusedBuilder(target.BuilderType);
            }

            if (target.HasBuilder())
            {
                return true;
            }

            return false;

        }

        protected override bool CanTryToMoveToThisState(IBuildingParty buildingParty, BuildTarget target, StarBotDotNet.ProxyBot bot, UnitDictionary currentUnits, int currentTime)
        {
            return true;
        }

        protected override void PrepareInitiationOfMovingToThisState(IBuildingParty buildingParty, BuildTarget target, StarBotDotNet.ProxyBot bot, UnitDictionary currentUnits, int currentTime)
        {

            
            
        }

        public override BuildStateEnum StateFrom
        {
            get { return BuildStateEnum.b0_Initial; }
        }

        public override BuildStateEnum StateTo
        {
            get { return BuildStateEnum.b2_BuilderAndResourcesAllocated; }
        }
    }
}
